<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>mockactivitymonitor_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_mockactivitymonitor_test.js.html">mockactivitymonitor_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview Tests for goog.ui.MockActivityMonitorTest.
<a name="line18"></a> * @author nnaze@google.com (Nathan Naze)
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>/** @suppress {extraProvide} */
<a name="line22"></a>goog.provide(&#39;goog.ui.MockActivityMonitorTest&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.events&#39;);
<a name="line25"></a>goog.require(&#39;goog.functions&#39;);
<a name="line26"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.recordFunction&#39;);
<a name="line28"></a>goog.require(&#39;goog.ui.ActivityMonitor&#39;);
<a name="line29"></a>goog.require(&#39;goog.ui.MockActivityMonitor&#39;);
<a name="line30"></a>
<a name="line31"></a>goog.setTestOnly(&#39;goog.ui.MockActivityMonitorTest&#39;);
<a name="line32"></a>
<a name="line33"></a>var googNow = goog.now;
<a name="line34"></a>var monitor;
<a name="line35"></a>var recordedFunction;
<a name="line36"></a>var replacer;
<a name="line37"></a>
<a name="line38"></a>function setUp() {
<a name="line39"></a>  monitor = new goog.ui.MockActivityMonitor();
<a name="line40"></a>  recordedFunction = goog.testing.recordFunction();
<a name="line41"></a>
<a name="line42"></a>  goog.events.listen(
<a name="line43"></a>      monitor,
<a name="line44"></a>      goog.ui.ActivityMonitor.Event.ACTIVITY,
<a name="line45"></a>      recordedFunction);
<a name="line46"></a>}
<a name="line47"></a>
<a name="line48"></a>function tearDown() {
<a name="line49"></a>  goog.dispose(monitor);
<a name="line50"></a>  goog.now = googNow;
<a name="line51"></a>}
<a name="line52"></a>
<a name="line53"></a>function testEventFireSameTime() {
<a name="line54"></a>  goog.now = goog.functions.constant(1000);
<a name="line55"></a>
<a name="line56"></a>  monitor.simulateEvent();
<a name="line57"></a>  assertEquals(1, recordedFunction.getCallCount());
<a name="line58"></a>
<a name="line59"></a>  monitor.simulateEvent();
<a name="line60"></a>  assertEquals(2, recordedFunction.getCallCount());
<a name="line61"></a>}
<a name="line62"></a>
<a name="line63"></a>function testEventFireDifferingTime() {
<a name="line64"></a>  goog.now = goog.functions.constant(1000);
<a name="line65"></a>  monitor.simulateEvent();
<a name="line66"></a>  assertEquals(1, recordedFunction.getCallCount());
<a name="line67"></a>
<a name="line68"></a>  goog.now = goog.functions.constant(1001);
<a name="line69"></a>  monitor.simulateEvent();
<a name="line70"></a>  assertEquals(2, recordedFunction.getCallCount());
<a name="line71"></a>}
<a name="line72"></a>
<a name="line73"></a>function testDispatchEventReturnValue() {
<a name="line74"></a>  assertTrue(monitor.dispatchEvent(goog.ui.ActivityMonitor.Event.ACTIVITY));
<a name="line75"></a>  assertEquals(1, recordedFunction.getCallCount());
<a name="line76"></a>}
<a name="line77"></a>
<a name="line78"></a>function testDispatchEventPreventDefault() {
<a name="line79"></a>  // Undo the listen call in setUp.
<a name="line80"></a>  goog.events.unlisten(
<a name="line81"></a>      monitor,
<a name="line82"></a>      goog.ui.ActivityMonitor.Event.ACTIVITY,
<a name="line83"></a>      recordedFunction);
<a name="line84"></a>
<a name="line85"></a>  // Listen with a function that cancels the event.
<a name="line86"></a>  goog.events.listen(
<a name="line87"></a>      monitor,
<a name="line88"></a>      goog.ui.ActivityMonitor.Event.ACTIVITY,
<a name="line89"></a>      function(e) {
<a name="line90"></a>        e.preventDefault();
<a name="line91"></a>      });
<a name="line92"></a>
<a name="line93"></a>  assertFalse(monitor.dispatchEvent(goog.ui.ActivityMonitor.Event.ACTIVITY));
<a name="line94"></a>}
</pre>


</body>
</html>
